package com.yourblog.jerry_springboot.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yourblog.jerry_springboot.vo.FileVo;
import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName test
 * @Author WYQ
 * @Date 2020-11-03 11:41
 * @Version1.0
 **/
public class test {
    @Test
    public void read() throws Exception {
        String name = "D:\\file\\listDict.txt";
        BufferedReader br = new BufferedReader(new FileReader(name));//构造一个BufferedReader类来读取文件
        List<String> list = new ArrayList<>();
        String s = null;
        while((s = br.readLine())!=null){//使用readLine方法，一次读一行
            if (StringUtils.isNotBlank(s)) {
                list.add(s);
            }
        }
        br.close();
        list.forEach(System.out::println);
    }

    @Test
    public void write() throws Exception {
        String name = "D:\\file\\listDict.txt";
        BufferedWriter br = new BufferedWriter(new FileWriter(name));//构造一个BufferedReader类来读取文件
        List<String> list = new ArrayList<>();
        list.add("1.txt");
        list.add("2.txt");
        list.add("3.txt");
        for (String str:list) {
            br.write(str+"\n");
        }
        br.close();
    }
}
